package com.example.lishop.controller

import com.example.lishop.base.MyResponse
import com.example.lishop.entity.BProductTagEntity
import com.example.lishop.exception.ExceptEnum
import com.example.lishop.service.impl.ProductTagServiceImpl
import com.example.lishop.util.SnowflakeUtil
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.util.Assert
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*

/**
 * Created on 2021/3/14 18:28
 * @author shuguo
 * 商品
 */
@Api(value = "/ProductTag", tags = arrayOf("商品标签接口"))
@RestController
@RequestMapping("/productTag")
class ProductTagCtl {

    @Autowired
    lateinit var service: ProductTagServiceImpl

    @ApiOperation(value = "添加商品标签")
    @PostMapping(value = ["/add"])
    fun add(@RequestBody bean: BProductTagEntity) : MyResponse<BProductTagEntity> {
        bean.productTagId = ""+ SnowflakeUtil.instance.nextId(3)
        return MyResponse(200, "添加成功", service.add(bean))
    }

    @ApiOperation(value = "修改商品标签")
    @PostMapping(value = ["/update"])
    fun update(@RequestBody @Validated bean:BProductTagEntity) : MyResponse<BProductTagEntity> {
        service.update(bean)
        return MyResponse(200, "修改成功", detail(bean).data)
    }

    @ApiOperation(value = "商品标签列表")
    @PostMapping(value = ["/list"])
    fun list() : MyResponse<List<BProductTagEntity>> {
        return MyResponse(200, "请求列表成功", service.list())
    }

    @ApiOperation(value = "删除商品标签")
    @PostMapping(value = ["/del"])
    fun del(@RequestBody @Validated bean:BProductTagEntity) : MyResponse<Unit> {
        return MyResponse(200, "删除成功", service.del(bean))
    }

    @ApiOperation(value = "查询商品标签详情")
    @PostMapping(value = ["/detail"])
    fun detail(@RequestBody @Validated bean:BProductTagEntity) : MyResponse<BProductTagEntity> {
        return MyResponse(200, "查找成功", service.detail(bean))
    }
}
